package com.xw.p03_SingletonPattern;

/**
 * @author XW
 * @data 2023/12/4 15:05
 * @description 饿汉模式
 */
public class HungryEmperor {
    private static volatile HungryEmperor hungryEmperor;

    private HungryEmperor() {
    }

    public static HungryEmperor getHungryEmperor() {
        if(null == hungryEmperor){
            synchronized (HungryEmperor.class){
                if (null == hungryEmperor){
                    hungryEmperor = new HungryEmperor();
                    System.out.println("饿汉模式创建了");
                }
            }
        }
        return hungryEmperor;
    }

    public  void emperorInfo(){
        System.out.println("我就是皇帝"+hungryEmperor.hashCode());
    }
}
